<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<div id="app">
    <h1>用户注册</h1>
    <p>用户名：<input type="text" v-model="username"/></p>
    <p>密码：<input type="text" v-model="password"/></p>
    <button @click="submit">注册</button>
    <p><a href="./login.html">去登录</a></p>
</div>

<script src="./js/vue.js"></script>
<script src="./js/axios.js"></script>
<script src="./js/constant.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            username: "",
            password: ""
        },
        methods: {
            submit() {
                let parmas = new URLSearchParams()
                parmas.append("username", this.username)
                parmas.append("password", this.password)

                axios.post(baseUrl + "buybuybuy/api/user/register", parmas).then((res) => {
                    let data = res.data;
                    if (data.success) {
                        alert("注册成功")

                        location = "./buy.html"
                    } else {
                        alert(data.msg)
                    }
                })
            }
        }
    })
</script>
</body>

</html>